package com.khiker.linklist;

public class P203_RemoveElements {

	public ListNode removeElements_1(ListNode head, int val) {
		head = new ListNode(-1, head);
		ListNode cur = head;
		while (cur.next != null) {
			if (cur.next.val == val) {
				cur.next = cur.next.next;
			} else {
				cur = cur.next;
			}
		}
		return head.next;
	}


	public ListNode removeElements(ListNode head, int val) {
		if (head == null) {
			return null;
		}
		head.next = removeElements(head.next, val);
		return head.val == val ? head.next : head;
	}
}
